**Non-Pecuniary Benefits Paper - Regression Analysis***

/*
The following code builds performs the regressions underlying
Tables 2-6, Internet Appendix Tables D.1-D.7, Figure 1, and Figures A.1, D.1

***To run this file you need the following base .dta files:
1) Regression_Analysis_pseudo.dta
2) QOL_Predictors_BP.dta
3) BLS_Super_input_concentration.dta
4) BLS_Super_output_concentration.dta"


The file also requires the following files for generating the map behind figure 1,
the mapping files are from the US Census.

The following variables are proprietary to Pratt Stats or ReferenceUSA and have been randomized. In addition only a subset of the data has been provided.
CompanyAge EmployeeNumber NetSales AskPrice MVICPrice l_Price l_Sales hqs_over_1M hqs_over_1M_scaled OperatingProfit OPtoS l_OPtoS Assets l_Assets Q l_Q l_assets cash_consideration
Private EmployAgr AssumedLease survivedto2015 EmployAgr_BP

*/


********************************************************************************
******************* Primary Regression File  ***********************************
********************************************************************************
use "${Data}\Regression_Analysis_pseudo.dta", clear
	
********************************************************************************
*************   Transaction Count Mapping and Histogram   **********************
********************************************************************************
preserve
*Create CBSA mapping file
shp2dta using "${Data}\Mapping\tl_2015_us_cbsa.shp", database("${Data}\Mapping\uscbsadb2015") coordinates("${Data}\Mapping\uscbsacoord2015") genid(id) replace
*Merge to state names for exlcuding HI, AK, and other territories
use "${Data}\Mapping\usstates.dta",clear
replace order = _n
merge _ID using "${Data}\Mapping\usstate_names.dta"
drop _m
sort order
sort _ID
save, replace


*Collapse data for transaction counts
use "${Data}\Regression_Analysis_pseudo.dta", clear
drop if ID==.
gen counter = 1
*Drop AK and HI for graphing purposes
gen dropstate= SaleState=="HI"|SaleState=="AK"
collapse (sum) counter (mean) dropstate, by(cbsa cbsaname)
rename cbsa CBSAFP
tostring CBSAFP, replace
save "${Data}\transaction_counts_cbsa.dta", replace

*Merge with database file to generate long/lat
mmerge CBSAFP using "${Data}\Mapping\uscbsadb2015.dta"
/*
For ones with missing long/lat, use central county's from: https://www.census.gov/geographies/reference-files/time-series/geo/gazetteer-files.2012.html#list-tab-264479560
and assign to closest Metro
*/
destring INTPTLAT , replace
destring INTPTLON , replace
destring CBSAFP, replace
rename CBSAFP cbsa
mmerge cbsa using "${Data}\Mapping\Missing_CBSA_mapping.dta", ukeep(cbsa MappedCBSA MappedID) update
drop if counter==.
drop if dropstate==1
replace MappedCBSA=cbsa if MappedCBSA==.
replace MappedID = id if MappedID==.
drop id
rename MappedID id
drop if missing(MappedCBSA)
collapse (sum) counter , by(MappedCBSA id)
egen total_count=total(counter)
*Generate proportional for graphing
gen proportion_count=counter/total_count

colorpalette spmap greys, n(12) nograph
local colors `r(p)'

spmap counter using "${Data}\Mapping\uscbsacoord2015" , ///
   id(id) ndfc(white)  fcolor("`colors'")   ocolor(gs12 ..) /// 
   clm(custom) clbreaks(0 5 10 25 50 100 200 500) ///
   polygon(select(drop if STATEFP =="02" | STATEFP =="15" | STATEFP =="72" | STATEFP =="78"| STATEFP =="69"| STATEFP =="66" | STATEFP =="60") ///  
   data("${Data}\Mapping\usstates.dta" ) )
restore 

***Histogram - Internet Appendix Figure A.1
use "${Data}\Regression_Analysis_pseudo.dta", clear
drop if ID==.
drop if year>2012
gen counter = 1
collapse (sum) counter, by(year)
egen total_count = total(counter)
graph drop _all
twoway bar counter year, bcolor(gs) /// 
	graphregion(fcolor(white) lcolor(none) ifcolor(none) ilcolor(none)) plotregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) ///
	xtitle("{bf:Year of Transaction}") ytitle("{bf: Frequency}") ///
	ylabel(0(200)1000,format(%8.0f) nogrid) xscale(range(1995 2012)) xlabel(1995(3)2010) ///
	name(transactionhist) 
graph export "${Tables}\transaction_hist.pdf", name(transactionhist) replace
	  
	  
********************************************************************************
*********************   Control Macros  ****************************************
********************************************************************************
use "${Data}\Regression_Analysis_pseudo.dta", clear
global fin_controls l_Sales OPtoS EmployAgr AssumedLease
global local_controls cbsa_bachelors_or_higher l_pop_cbsa l_pop_density l_cbsa_tax l_median_house l_pcpi  ///
 d5_pop_cbsa d5_pcpi_cbsa d5_employment d5_med_house_val_cbsa
global channels cbsa_percent_households_200k transactions_cbsa_avg_sc local_industry_conc
global future_growth f5_pop_cbsa f5_pcpi_cbsa f5_employment f5_med_house_val_cbsa

*Generate asking discount
gen asking_discount=MVICPrice/AskPrice


********************************************************************************
********************   Summary Stats Comp  *************************************
********************************************************************************

preserve
mmerge cbsa year using "${Data}\QOL_Predictors_BP.dta"
drop if _merge==2
*Comparison across CBSAs
reghdfe l_Price $fin_controls BP_CBSA $channels $local_controls , cluster(cbsa) absorb(ind_code_48##year state_id)
keep if e(sample)==1

replace NetSales=NetSales/1000
replace Assets=Assets/1000
replace MVICPrice=MVICPrice/1000
replace pop_cbsa = pop_cbsa/1000
replace median_house_value_CBSA_imputed = median_house_value_CBSA_imputed/1000

*BP Predictors
gen l_Sunlight = ln(cbsa_Mean_Jan_Sunlight)
gen l_Humidity = ln(1+cbsa_Mean_July_Humidity)
replace l_pop_1900 = ln(1+pop_1900)
replace l_Precipitation =  ln(1+Precipitation_clean)
replace l_Greater_90 = ln(1+Greater_90_clean)
replace l_Less_20 = ln(1+Less_20_clean)
rename cbsa_l_Percent_Water l_Water 
rename cbsa_Topography_Code Topography_Code


label var cbsa_percent_households_200k "\% of Households with Inc.$>$200K"
label var cbsa_bachelors_or_higher "\% of Pop. w/ Bachelors or higher"
label var median_house_value_CBSA_imputed "Median Home Price ('000)"
label var pop_cbsa "Population ('000')"
label var pop_density "Population Density"
label var pcpi "Per Capita Income"
label var cbsa_tax "Tax Burden"
label var d5_pop "5-year Pop. Growth"
label var d5_employment "5-Year Job Growth"
label var d5_pcpi "5-Year PCPI Growth"
label var d5_med_house_val "5-Year Home Price Growth"
label var transactions_cbsa_avg_sc "Avg Transactions in CBSA per year/ \#('000) Firms"
label var MVICPrice "Transaction Price ('000)"
label var NetSales "Net Sales ('000')"
label var asking_discount "Discount to Ask (\%)"
label var survivedto2015 "Survived to 2015"
label var OPtoS "Operating Profit / Sales"
label var EmployeeNumber "Number of Employees"
label var AssumedLease "Assumed Lease"

*BP Predictors
label var l_pop_1900 "Log(Population in 1900)"
label var l_Precipitation  "Log(Precipitation)"
label var l_Greater_90 "Log(Number of Days > 90 F)"
label var l_Less_20  "Log(Number of Days <20 F)"
label var l_Sunlight "Log(Average January Sun)"
label var l_Humidity "Log(Average July Humidity)"
label var l_Water  "Log(\% of area covered by water)"
label var Topography_Code "Topographical Variation"
label var Percent_UnHealthy_Air "Percent of Days with Unhealthy Air"
label var Student_to_Teacher "Student-Teacher Ratio"
label var property_crime_rate "Property Crimes per 100K"
label var violent_crime_rate  "Violent Crimes per 100K"
label var recreation_estab_pc "Recreation Establishments per 1,000"
label var eating_estab_pc "Eating Establishments per 1,000"
label var drinking_estab_pc "Drinking Establishments per 1,000"


*Combined 
file open table_output using "${Tables}\summary_stats_combined.tex", write replace
file write table_output "\toprule & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Std. Dev.}  & \multicolumn{1}{c}{Median} & \multicolumn{1}{c}{BP=0} & \multicolumn{1}{c}{BP=1} & \multicolumn{1}{c}{Difference}  \\" _n
file write table_output " & (1). & (2) & (3) & (4) & (5) & (6) \\ \midrule " _n

file write table_output "\textbf{Firm Level} & & & & & & \\ \cmidrule{1-1}" _n
foreach var of varlist MVICPrice NetSales OPtoS CompanyAge EmployeeNumber EmployAgr AssumedLease asking_discount Private survived {
	file write table_output "`: variable label `var'' & "
	sum `var' , det
	local out = `r(mean)'
	file write table_output "`: di %9.3f `out'' & "
	local out = `r(sd)'
	file write table_output "`: di %9.3f `out'' & "
	local out = `r(p50)'
	file write table_output "`: di %9.3f `out'' & "
	sum `var' if BP_CBSA==0
	local out = `r(mean)'
	file write table_output "`: di %9.3f `out'' & "
	sum `var' if BP_CBSA==1
	local out = `r(mean)'
	file write table_output "`: di %9.3f `out'' & "
	reghdfe `var' BP_CBSA, noabsorb
	qui local t = _b[BP_CBSA]/_se[BP_CBSA]
	qui local diff = _b[BP_CBSA]
	file write table_output "`: di %9.3f `diff'' \\ " _n
}

file write table_output "\textbf{CBSA Level} & & & & & & \\ \cmidrule{1-1}" _n
foreach var of varlist cbsa_bachelors_or_higher pop_cbsa pop_density cbsa_tax median_house_value_CBSA_imputed pcpi d5_pop_cbsa d5_pcpi_cbsa d5_employment d5_med_house_val_cbsa cbsa_percent_households_200k transactions_cbsa_avg_sc local_industry_conc l_pop_1900 l_Precipitation l_Greater_90 l_Less_20 l_Sunlight l_Humidity l_Water Topography_Code {
  	file write table_output "`: variable label `var'' & "
	sum `var' , det
	local out = `r(mean)'
	file write table_output "`: di %9.3f `out'' & "
	local out = `r(sd)'
	file write table_output "`: di %9.3f `out'' & "
	local out = `r(p50)'
	file write table_output "`: di %9.3f `out'' & "
	sum `var' if BP_CBSA==0
	local out = `r(mean)'
	file write table_output "`: di %9.3f `out'' & "
	sum `var' if BP_CBSA==1
	local out = `r(mean)'
	file write table_output "`: di %9.3f `out'' & "
	reghdfe `var' BP_CBSA, noabsorb cluster(cbsa)
	qui local t = _b[BP_CBSA]/_se[BP_CBSA]
	qui local diff = _b[BP_CBSA]
	file write table_output "`: di %9.3f `diff'' \\ " _n
}  
file write table_output "\bottomrule " _n
file close table_output

restore
 
*********************************************************************************
******************** THIS RUNS REGRESSIONS FOR BASELINE VALUATION ***************
*********************************************************************************
eststo clear
eststo:	reghdfe l_Price $fin_controls , cluster(cbsa) absorb(ind_code_48 year)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "No"

eststo:	reghdfe l_Price $fin_controls BP_CBSA, cluster(cbsa) absorb(ind_code_48 year)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "No"
  	
eststo:	reghdfe l_Price $fin_controls BP_CBSA $local_controls , cluster(cbsa) absorb(ind_code_48 year)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "No"
 
eststo:	reghdfe l_Price $fin_controls BP_CBSA $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"

eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	
eststo:	reghdfe l_Price $fin_controls BM_cbsa above_median_pcpi##BP_CBSA  cbsa_bachelors_or_higher l_pop_cbsa l_pop_density l_cbsa_tax l_median_house  ///
 d5_pop_cbsa d5_pcpi_cbsa d5_employment d5_med_house_val_cbsa, cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	
	esttab * using "${Tables}\baseline.tex", booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(industry state year  r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
		labels("Industry FE" "Year FE" "State FE"  "Adjusted R2" "Obs.")) /// 
		label mtitles("Firm Financials" "Best Places" "Geographic Controls" "State FE" "Local B/M" "BP Interacted") nonotes
	
***********************************************************************************
************** THIS RUNS REGRESSIONS FOR TABLE WITH ADDITIONAL CHANNELS *********** 
***********************************************************************************
	
eststo clear
eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local IndustryYear "No"
eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA local_industry_conc $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local IndustryYear "No"
eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA  cbsa_percent_households_200k $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local IndustryYear "No"
eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA  transactions_cbsa_avg_sc $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local IndustryYear "No"
reghdfe l_Price $fin_controls BM_cbsa BP_CBSA  $channels $local_controls , cluster(cbsa) absorb(ind_code_48 year state_id)
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local IndustryYear "No"
	
***With Industry x Year FE
eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA  $channels $local_controls , cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local IndustryYear "Yes"
	
esttab * using "${Tables}\additional_channels.tex", booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(industry state year IndustryYear r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
		labels("Industry FE" "Year FE" "State FE" "Industry x Year" "Adjusted R2" "Obs.")) /// 
		keep(BP_CBSA  $channels) ///
		label mtitles("Agglomeration" "Home Bias" "Liquidity" "All" "Industry x Year") nonotes
	
			
********************************************************************************
******************* THIS RUNS REGRESSIONS FOR TABLES 5 & 6 ********************* 
********************************************************************************
			
***Buyer-Type***
eststo clear
*Private*
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls if Private==1, ///
	cluster(cbsa) absorb(ind_code_48##year state_id)
	 gen sample_private=e(sample)
		estadd local geographic "Yes"
		estadd local additional "Yes"
		estadd local state "Yes"
		estadd local IndustryYear "Yes"
	*Public*
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls if Private==0, /// 
	cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local geographic "Yes"
		estadd local additional "Yes"
		estadd local state "Yes"
		estadd local IndustryYear "Yes"
		
	***ROBUSTNESS CHECK FOR BUYER TYPE***
		*Private*
		eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
		if Private==1&middle==1, cluster(cbsa) absorb(ind_code_48##year state_id)
			estadd local geographic "Yes"
			estadd local additional "Yes"
			estadd local state "Yes"
			estadd local IndustryYear "Yes"
		*Public*
		eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
		if Private==0&middle==1, cluster(cbsa) absorb(ind_code_48##year state_id)
			estadd local geographic "Yes"
			estadd local additional "Yes"
			estadd local state "Yes"
			estadd local IndustryYear "Yes"
			
		esttab * using "${Tables}\buyer-type.tex", booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(geographic additional state IndustryYear r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
		labels("Geographic Controls" "Additional Controls" "State FE" "Industry x Year FE" "Adj. \(R^2\)" "Obs.")) /// 
		keep(BP_CBSA  $fin_controls) ///
		label mtitles("Full - Private" "Full Public" "Middle Private" "Middle Public") nonotes
			
		
***Size***
eststo clear
	*Small*
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if psize_20==1, cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local geographic "Yes"
		estadd local additional "Yes"
		estadd local state "Yes"
		estadd local IndustryYear "Yes"
		
	*Medium*
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if middle==1, cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local geographic "Yes"
		estadd local additional "Yes"
		estadd local state "Yes"
		estadd local IndustryYear "Yes"
		
	*Large*
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if psize_100==1, cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local geographic "Yes"
		estadd local additional "Yes"
		estadd local state "Yes"
		estadd local IndustryYear "Yes"
		
	esttab * using "${Tables}\size-type.tex", booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(geographic additional state IndustryYear r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
		labels("Geographic Controls" "Additional Controls" "State FE" "Industry x Year FE" "Adj. \(R^2\)" "Obs.")) /// 
		keep(BP_CBSA  $fin_controls) ///
		label mtitles("Small" "Middle" "Large") nonotes	
		
		
	*Fully interacted controls with size buckets
	global sz_interact_fin_controls c.l_Sales##middle c.OPtoS##middle c.EmployAgr##middle c.AssumedLease##middle c.l_Sales##psize_100 c.OPtoS##psize_100 c.EmployAgr##psize_100 c.AssumedLease##psize_100
	global sz_interact_local_controls c.cbsa_bachelors_or_higher##middle c.l_pop_cbsa##middle c.l_pop_density##middle c.l_cbsa_tax##middle c.l_median_house##middle c.l_pcpi##middle  ///
	 c.d5_pop_cbsa##middle c.d5_pcpi_cbsa##middle c.d5_employment##middle c.d5_med_house_val_cbsa##middle ///
	 c.cbsa_bachelors_or_higher##psize_100 c.l_pop_cbsa##psize_100 c.l_pop_density##psize_100 c.l_cbsa_tax##psize_100 c.l_median_house##psize_100 c.l_pcpi##psize_100  ///
	 c.d5_pop_cbsa##psize_100 c.d5_pcpi_cbsa##psize_100 c.d5_employment##psize_100 c.d5_med_house_val_cbsa##psize_100
	global sz_interact_channels c.cbsa_percent_households_200k##middle c.transactions_cbsa_avg_sc##middle c.local_industry_conc##middle ///
	 c.cbsa_percent_households_200k##psize_100 c.transactions_cbsa_avg_sc##psize_100 c.local_industry_conc##psize_100
	 
	 *Fully interacted controls with private/public buckets
	global private_interact_fin_controls c.l_Sales##Private c.OPtoS##Private c.EmployAgr##Private c.AssumedLease##Private 
	global private_interact_local_controls c.cbsa_bachelors_or_higher##Private c.l_pop_cbsa##Private c.l_pop_density##Private c.l_cbsa_tax##Private c.l_median_house##Private c.l_pcpi##Private  ///
	 c.d5_pop_cbsa##Private c.d5_pcpi_cbsa##Private c.d5_employment##Private c.d5_med_house_val_cbsa##Private 
	global private_interact_channels c.cbsa_percent_households_200k##Private c.transactions_cbsa_avg_sc##Private c.local_industry_conc##Private
	 
	 *Interactions on size
	est clear
	eststo Size: reghdfe l_Price BP_CBSA##middle BP_CBSA##psize_100 ///
		$sz_interact_fin_controls $sz_interact_local_controls $sz_interact_channels ///
		c.BM_cbsa##psize_100 c.BM_cbsa##middle, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	estadd local interacted "Yes"


	*All firms
	eststo Private: reghdfe l_Price BP_CBSA##Private $private_interact_fin_controls ///
		$private_interact_local_controls $private_interact_channels Private##c.BM_cbsa, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	estadd local interacted "Yes"

	*Restricting only to middle
	eststo PrivateSize: reghdfe l_Price BP_CBSA##Private $private_interact_fin_controls ///
		$private_interact_local_controls $private_interact_channels c.BM_cbsa##Private if middle==1, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	estadd local interacted "Yes"

	esttab * using "${Tables}\interactions.tex", booktabs ///
			replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
			cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
			stats(industry state fin geo additional interacted  r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.2fc %9.0fc) ///
			labels("Industry x Year FE" "State FE" "Financial Controls" "Geographic Controls" "Additional Controls" "Interacted Controls"  "Adjusted R2" "Obs.")) /// 
			keep(1.BP_CBSA 1.BP_CBSA#1.middle 1.BP_CBSA#1.psize_100 1.BP_CBSA#1.Private ) coeflabels(1.BP_CBSA "Best Place" 1.BP_CBSA#1.middle "Best Place x Middle " 1.BP_CBSA#1.psize_100 "Best Place x Top" 1.BP_CBSA#1.Private "Best Place x Private")  ///
			label mtitles("Size" "Public/Private" "Public/Private Size") nonotes

***********************************************************************************
********** THIS RUNS REGRESSIONS FOR TABLE D.1 and D.2 Alt Size Checks************* 
***********************************************************************************	
			
*Different size cutoffs - Table D.1
	eststo clear
	*IQR
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls /// 
		if psize_25==1, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls /// 
		if psize_25_75==1, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls /// 
		if psize_75_100==1, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
	*Terciles
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls /// 
		if psize_33==1, cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls /// 
		if psize_66==1, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls /// 
		if psize_999==1, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
		
		esttab * using "${Tables}\Robustness_Size.tex", booktabs ///
			replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
			cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
			stats(industry state fin geo additional  r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.2fc %9.0fc) ///
			labels("Industry x Year FE" "State FE" "Financial Controls" "Geographic Controls" "Additional Controls"  "Adjusted R2" "Obs.")) /// 
			keep(BP_CBSA) coeflabels(BP_CBSA "Best Place")  ///
			label mtitles("Low" "Medium" "High" "Low" "Medium" "High") nonotes
			
***Additional Cutoffs - Table D.2***		
	eststo clear
	*Focusing on subset of firms with prices between 500K and 2M
	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels if MVICPrice<500000, absorb(ind_code_48##year state_id  ) cluster(cbsa)
		estadd local IndustryYear "Yes"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels if MVICPrice>=500000 & MVICPrice<=2000000, absorb(ind_code_48##year state_id  ) cluster(cbsa)
		estadd local IndustryYear "Yes"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels if MVICPrice>2000000, absorb(ind_code_48##year state_id  ) cluster(cbsa)
		estadd local IndustryYear "Yes"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
		
	esttab * using "${Tables}\OtherSizeBuckets.tex", booktabs ///
			replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
			cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
			stats(fin geo additional state IndustryYear r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
			labels("Financial Controls" "Geographic Controls" "Additional Controls" "State FE" "Industry x Year FE" "Adj. \(R^2\)" "Obs.")) /// 
			keep(BP_CBSA) ///
			label mtitles("$ < \$500K$" "\$500K-\$2M" "$>\$2MM") nonotes	
		
	
***********************************************************************************
************** THIS RUNS REGRESSIONS FOR TABLE D.3 ROBUSTNESS CHECKS ************** 
***********************************************************************************			
gen recession=0
replace recession=1 if SaleDate>=mdy(3,1,2001)&SaleDate<=mdy(11,30,2001)
replace recession=1 if SaleDate>=mdy(12,1,2007)&SaleDate<=mdy(6,30,2009)

		
*Buckets for FEs
	xtile dec_transactions_cbsa_avg_sc=transactions_cbsa_avg_sc, nq(10)

eststo clear
***Time Period***
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if year<=2004, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
			
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if year>2004, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
	***In and Out of Recessions***
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if recession==1, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
		
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if recession==0, cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
		
		
***Exclude California***
	eststo:	reghdfe l_Price $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
	if SaleState!="CA", cluster(cbsa) absorb(ind_code_48##year state_id)
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"

***5-year forward growth stuff***
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA  $channels $local_controls ///
	 $future_growth, ///
	 absorb(ind_code_48##year state_id) cluster(cbsa) 
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
*Cash Consideration
	eststo: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA  $channels $local_controls ///
	 cash_consideration, ///
	 absorb(ind_code_48##year state_id) cluster(cbsa) 
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
*With FEs for local and channel controls:
		eststo: reghdfe l_Price $fin_controls BP_CBSA BM_cbsa, cluster(cbsa) ///
		absorb(ind_code_48 year state_id dec_cbsa_bachelors_or_higher dec_l_pop_cbsa dec_l_pop_density /// 
		dec_l_cbsa_tax dec_l_median_house dec_l_pcpi dec_d5_pop_cbsa dec_d5_pcpi_cbsa ///
		dec_d5_employment dec_d5_med_house_val_cbsa dec_cbsa_percent_households_200k dec_local_industry_conc  dec_transactions_cbsa_avg_sc)
		estadd local industry "Yes"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "FE"
		estadd local additional "FE"
		
*Survival/Discount Controls
	eststo: reghdfe l_Price BP_CBSA  $fin_controls BM_cbsa $local_controls $channels asking_discount survivedto2015, absorb(ind_code_48##year state_id) cluster(cbsa) 
	estadd local industry "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	

	esttab * using "${Tables}\Robustness.tex" , booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(industry state fin geo additional  r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.2fc %9.0fc) ///
		labels("Industry x Year FE" "State FE" "Financial Controls" "Geographic Controls" "Additional Controls"  "Adjusted R2" "Obs.")) /// 
		keep(BP_CBSA $future_growth asking_discount survivedto2015 ) coeflabels(BP_CBSA "Best Place" f5_pop_cbsa "5-Yr. Pop. Growth" f5_pcpi_cbsa  "5-Yr. PCPI Growth" f5_employment  "5-Yr. Emp. Growth" f5_med_house_val_cbsa "5-Yr. Home Price Growth" asking_discount "Asking Discount" survivedto2015 "Survival")  ///
		label mtitles("Early" "Late" "Recession" "No Recession" "No CA" "Forward Growth" "Cash Consideration" "Control FEs" "Survival/Discount Controls") nonotes
		
		


		
***********************************************************************************
************** THIS RUNS REGRESSIONS FOR Alternative BP Measures Table D.5 ********
***********************************************************************************	

*** AdjQOL_Robustness -  OLS   
	sum q_1990
	gen q_1990_scaled=1+q_1990+abs(r(min))
	sum q_ind_1990
	gen q_ind_1990_scaled=1+q_ind_1990+abs(r(min))
	sum ax_true_1990
	gen ax_true_1990_scaled=1+ax_true_1990+abs(r(min))
	sum ax_ind_1990
	gen ax_ind_1990_scaled=1+ax_ind_1990+abs(r(min))

	gen QOL_Production_1990 = q_1990_scaled / ax_true_1990_scaled
	gen QOL_ind_Production_1990 = q_ind_1990_scaled / ax_ind_1990_scaled

	winsor2 QOL_Production_1990, cuts(1 99)
	winsor2 QOL_ind_Production_1990, cuts(1 99)

	global QOL_Measure QOL_Production_1990_w

	eststo clear

	eststo adjQOLbase: reghdfe l_Price $QOL_Measure $fin_controls BM_cbsa $channels $local_controls $future_growth , ///
		cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
		
	eststo adjQOLbasePrivate: reghdfe l_Price $QOL_Measure $fin_controls BM_cbsa $channels $local_controls $future_growth if Private==1, ///
		cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

	eststo adjQOLbasePublic: reghdfe l_Price $QOL_Measure $fin_controls BM_cbsa $channels $local_controls $future_growth if Private==0, ///
		cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

	eststo adjQOLbaseSmall: reghdfe l_Price $QOL_Measure $fin_controls BM_cbsa $channels $local_controls $future_growth if psize_20==1, ///
		cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
		
	eststo adjQOLbaseMedium: reghdfe l_Price $QOL_Measure $fin_controls BM_cbsa $channels $local_controls $future_growth if middle==1, ///
		cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
		
	eststo adjQOLbaseLarge: reghdfe l_Price $QOL_Measure $fin_controls BM_cbsa $channels $local_controls $future_growth if psize_100==1, ///
		cluster(cbsa) absorb(ind_code_48##year state_id)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

***Historic BP***
	label var BP_CBSA_90_91_clean "Best Place (1990-1991)"

	eststo HistBPbase: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA_90_91_clean $channels $local_controls $future_growth production_amenity, /// 
		absorb(ind_code_48##year state_id) cluster(cbsa)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

	eststo HistBPbasePrivate: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA_90_91_clean $channels $local_controls ///
		$future_growth production_amenity if Private==1, absorb(ind_code_48##year state_id) cluster(cbsa)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

	eststo HistBPbasePublic: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA_90_91_clean $channels $local_controls ///
		$future_growth production_amenity if Private==0, absorb(ind_code_48##year state_id) cluster(cbsa)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

		
	eststo HistBPbaseSmall: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA_90_91_clean $channels $local_controls ///
		$future_growth production_amenity if psize_20==1, absorb(ind_code_48##year state_id) cluster(cbsa)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"
		
	eststo HistBPbaseMedium: reghdfe l_Price $fin_controls BM_cbsa BP_CBSA_90_91_clean $channels $local_controls ///
		$future_growth production_amenity if middle==1, absorb(ind_code_48##year state_id) cluster(cbsa)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

	eststo HistBPbaseLarge : reghdfe l_Price $fin_controls BM_cbsa BP_CBSA_90_91_clean $channels $local_controls ///
		$future_growth production_amenity if psize_100==1, absorb(ind_code_48##year state_id) cluster(cbsa)
		estadd local industryYear "Yes"
		estadd local industry "No"
		estadd local year "No"
		estadd local state "Yes"
		estadd local fin "Yes"
		estadd local geo "Yes"
		estadd local additional "Yes"

	esttab adjQOLbase adjQOLbasePrivate adjQOLbasePublic adjQOLbaseSmall  adjQOLbaseMedium adjQOLbaseLarge ///  
			HistBPbase HistBPbasePrivate HistBPbasePublic HistBPbaseSmall HistBPbaseMedium  HistBPbaseLarge using "${Tables}\HistQOL_Robustness.tex" , booktabs ///
			replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
			cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
			stats(industryYear state fin geo additional  r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.2fc %9.0fc) ///
			labels("Industry x Year FE" "State FE" "Financial Controls" "Geographic Controls" "Additional Controls"  "Adjusted R2" "Obs.")) /// 
			keep($QOL_Measure BP_CBSA_90_91_clean l_Sales OPtoS EmployAgr AssumedLease ) ///
			coeflabels($QOL_Measure "QOL/Productivity (1990)" BP_CBSA_90_91_clean "Best Place (1990-1991)" l_Sales "Log(Sales)" OPtoS "Operating Profit / Sales" EmployAgr "Employment Agreement" AssumedLease "AssumedLease" )  ///
			label mtitles("Adj. QOL. - Full " "Adj QOL. Private" "Adj QOL. Public" "Adj QOL. Small" "Adj QOL. Medium" "Adj QOL. Large" ///
			"Historical BP - Full" "Historical BP - Private" "Historical BP - Publc" "Historical BP - Small" "Historical BP - Medium" "Historical BP - Large") nonotes
			
***********************************************************************************
*********************** Additional Side Tests - Table D.4 *************************
***********************************************************************************	
	
***Show BP does not predict asking discount***
label var asking_discount "Sold Price to Asking Price"

reg asking_discount $fin_controls BM_cbsa BP_CBSA, cluster(cbsa)	
	outreg2 using "${Tables}\asking_discount_and_survival.tex", replace alpha(.01 , .05 , .1) title(Regression of Asking Price and Survival) stats(coef se) /// 
	ct("Asking Discount - Simple") addtext("Industry FE", "No" , "State FE", "No", "Year FE" , "No", "Industry x Year FE", "No", "Controls", "No")  /// 
	label nocons nor2 noobs addstat(Adj. R2, e(r2_a), Obs., e(N)) excel keep(asking_discount $fin_controls BM_cbsa BP_CBSA) slow(1000)	
	
reghdfe asking_discount $fin_controls BM_cbsa BP_CBSA, absorb(ind_code_48 state_id year) cluster(cbsa)	
	outreg2 using "${Tables}\asking_discount_and_survival.tex", alpha(.01 , .05 , .1) title(Regression of Asking Price and Survival) stats(coef se) /// 
	ct("Asking Discount - Base") addtext("Industry FE", "Yes" , "State FE", "Yes", "Year FE" , "Yes", "Industry x Year FE", "No", "Controls", "No")  /// 
	label nocons nor2 noobs addstat(Adj. R2, e(r2_a), Obs., e(N)) excel keep(asking_discount $fin_controls BM_cbsa BP_CBSA) slow(1000)
	
reghdfe asking_discount $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
 production_amenity, absorb(ind_code_48##state_id year) cluster(cbsa)
 outreg2 using "${Tables}\asking_discount_and_survival.tex", alpha(.01 , .05 , .1) title(Regression of Asking Price and Survival) stats(coef se) /// 
	ct("Asking Discount - Full") addtext("Industry FE", "No" , "State FE", "Yes", "Year FE" , "No", "Industry x Year FE", "Yes", "Controls", "Yes")  /// 
	label nocons nor2 noobs addstat(Adj. R2, e(r2_a), Obs., e(N)) excel keep(asking_discount $fin_controls BM_cbsa BP_CBSA) slow(1000)

***Survival*** -- No More likely to survive
label var survivedto2015 "Survived to 2015"
reg survivedto2015 $fin_controls BM_cbsa BP_CBSA, cluster(cbsa)
outreg2 using "${Tables}\asking_discount_and_survival.tex", alpha(.01 , .05 , .1) title(Regression of Asking Price and Survival) stats(coef se) /// 
	ct("Survived? - Simple") addtext("Industry FE", "No" , "State FE", "No", "Year FE" , "No", "Industry x Year FE", "No", "Controls", "No")  /// 
	label nocons nor2 noobs addstat(Adj. R2, e(r2_a), Obs., e(N)) excel keep(survivedto2015 $fin_controls BM_cbsa BP_CBSA) slow(1000)
reghdfe survivedto2015 $fin_controls BM_cbsa BP_CBSA , absorb(ind_code_48 year state_id) cluster(cbsa)
outreg2 using "${Tables}\asking_discount_and_survival.tex", alpha(.01 , .05 , .1) title(Regression of Asking Price and Survival) stats(coef se) /// 
	ct("Survived? - Base") addtext("Industry FE", "No" , "State FE", "Yes", "Year FE" , "No", "Industry x Year FE", "Yes", "Controls", "No")  /// 
	label nocons nor2 noobs addstat(Adj. R2, e(r2_a), Obs., e(N)) excel keep(survivedto2015 $fin_controls BM_cbsa BP_CBSA) slow(1000)
reghdfe survivedto2015 $fin_controls BM_cbsa BP_CBSA $channels $local_controls ///
production_amenity, absorb(ind_code_48##year state_id) cluster(cbsa)
 outreg2 using "${Tables}\asking_discount_and_survival.tex", alpha(.01 , .05 , .1) title(Regression of Asking Price and Survival) stats(coef se) /// 
	ct("Survived? - Full") addtext("Industry FE", "No" , "State FE", "Yes", "Year FE" , "No", "Industry x Year FE", "Yes", "Controls", "Yes")  /// 
	label nocons nor2 noobs addstat(Adj. R2, e(r2_a), Obs., e(N)) excel keep(survivedto2015 $fin_controls BM_cbsa BP_CBSA) slow(1000)
			

***********************************************************************************
***************** THIS RUNS REGRESSIONS FOR MQ Ranks Table D.5 ********************
***********************************************************************************	

*Note these rankings are at state level

***Morgan Quinto***
label var MQ_rank "State Rank (Varying)"
label var MQ_1994 "State Rank (1994)"
replace MQ_rank=-MQ_rank+51
replace MQ_1994=-MQ_1994+51

eststo clear
eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_rank $channels $local_controls /// 
$future_growth production_amenity, absorb(ind_code_48##year) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"

eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_1994 $channels $local_controls ///
 $future_growth production_amenity, absorb(ind_code_48##year) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_rank $channels $local_controls ///
 $future_growth production_amenity if Private==1, absorb(ind_code_48##year) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_rank $channels $local_controls ///
 $future_growth production_amenity if Private==0, absorb(ind_code_48##year) cluster(cbsa)
estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_rank $channels $local_controls ///
 $future_growth production_amenity if psize_20==1, absorb(ind_code_48##year) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_rank $channels $local_controls ///
 $future_growth production_amenity if middle==1, absorb(ind_code_48##year) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
eststo: reghdfe l_Price $fin_controls BM_cbsa MQ_rank $channels $local_controls /// 
$future_growth production_amenity if psize_100==1, absorb(ind_code_48##year) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local state "No"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
esttab * using "${Tables}\MQ_Rankings.tex", booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(fin geographic additional state IndustryYear r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
		labels("Financial Controls" "Geographic Controls" "Additional Controls" "State FE" "Industry x Year FE" "Adj. \(R^2\)" "Obs.")) /// 
		keep(MQ_rank MQ_1994) ///
		label mtitles("Varying" "Static" "Private" "Public" "Small" "Middle" "Large") nonotes	
		
***********************************************************************************
***************** THIS RUNS REGRESSIONS FOR Weather Index Table D.7 ***************
***********************************************************************************	
		
***Weather Index***
label var w_and_t_index "Weather and Topography Index"
label var w_and_t_index_z_std "Weather and Topography Z-Index (Std.)"
label var w_and_t_index_50 "Weather and Topography Median-Index"
eststo clear

eststo: reghdfe l_Price $fin_controls BM_cbsa w_and_t_index_z_std if w_and_t_index_z_std!=., absorb(ind_code_48 year state_id) cluster(cbsa) 
	estadd local industryYear "No"
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "No"
	estadd local additional "No"
 
eststo: reghdfe l_Price $fin_controls BM_cbsa w_and_t_index_z_std $channels $local_controls if w_and_t_index_z_std!=., ///
 absorb(ind_code_48 year state_id) cluster(cbsa) 
	estadd local industryYear "No"
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
eststo: reghdfe l_Price $fin_controls BM_cbsa w_and_t_index_z_std $channels $local_controls production_amenity ///
 $future_growth if w_and_t_index_z_std!=., absorb(ind_code_48##year state_id) cluster(cbsa)  
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"
	
eststo: reghdfe l_Price $fin_controls BM_cbsa w_and_t_index if w_and_t_index_z_std!=., ///
 absorb(ind_code_48 year state_id) cluster(cbsa) 
	estadd local industryYear "No"
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "No"
	estadd local additional "No" 
eststo: reghdfe l_Price $fin_controls BM_cbsa w_and_t_index $channels $local_controls if w_and_t_index_z_std!=., ///
 absorb(ind_code_48 year state_id) cluster(cbsa) 
	estadd local industryYear "No"
	estadd local industry "Yes"
	estadd local year "Yes"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes" 
	
eststo: reghdfe l_Price $fin_controls BM_cbsa w_and_t_index $channels $local_controls production_amenity ///
 $future_growth if w_and_t_index_z_std!=., absorb(ind_code_48##year state_id) cluster(cbsa)  
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes" 
	
esttab * using "${Tables}\WeatherIndex.tex", booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(fin geographic additional industry year state IndustryYear r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.3fc %9.0fc) ///
		labels("Financial Controls" "Geographic Controls" "Additional Controls" "Industry FE" "Year FE" "State FE" "Industry x Year FE" "Adj. \(R^2\)" "Obs.")) /// 
		keep(w_and_t_index_z_std w_and_t_index) ///
		label mtitles("No Controls - Z" "Controls Z" "All Z" "Base Top 20" "Controls Top 20" "All Top 20") nonotes	
 
***********************************************************************************
******  Runs for Robustness Test on Concentration - Not Reported in Tables ********
***********************************************************************************	
	

*Tests related to concentration
	gen BLS_Super = 1011 if BLS_SuperSector=="Natural Resources and Mining"
	replace BLS_Super= 1012 if BLS_SuperSector=="Construction"
	replace BLS_Super= 1013 if BLS_SuperSector=="Manufacturing"
	replace BLS_Super= 1021 if BLS_SuperSector=="Trade, Transportation, and Utilities"
	replace BLS_Super= 1022 if BLS_SuperSector=="Information"
	replace BLS_Super= 1023 if BLS_SuperSector=="Financial Activities"
	replace BLS_Super= 1024 if BLS_SuperSector=="Professional and Business Services"
	replace BLS_Super= 1025 if BLS_SuperSector=="Education and Health Services"
	replace BLS_Super= 1026 if BLS_SuperSector=="Leisure and Hospitality"
	replace BLS_Super= 1027 if BLS_SuperSector=="Other Services"

	mmerge cbsa year BLS_Super using "${Data}\BLS_Super_input_concentration.dta"
	drop if _merge==2
	mmerge cbsa year BLS_Super using "${Data}\BLS_Super_output_concentration.dta"
	drop if _merge==2

	eststo clear
	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) ///
					cbsa_percent_households_200k transactions_cbsa_avg_sc ///
					weighted_input_concentration, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"

	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) ///
					cbsa_percent_households_200k transactions_cbsa_avg_sc local_industry_conc ///
					weighted_input_concentration, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"

	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) ///
					cbsa_percent_households_200k transactions_cbsa_avg_sc /// 
					weighted_output_concentration, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"

	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) ///
					cbsa_percent_households_200k transactions_cbsa_avg_sc local_industry_conc /// 
					weighted_output_concentration, absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"

	eststo: reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels ///
					weighted_input_concentration weighted_output_concentration , absorb(ind_code_48##year state_id) cluster(cbsa)
	estadd local industryYear "Yes"
	estadd local industry "No"
	estadd local year "No"
	estadd local state "Yes"
	estadd local fin "Yes"
	estadd local geo "Yes"
	estadd local additional "Yes"


esttab * using "${Tables}\InputOutput_Concentrations.tex" , booktabs ///
		replace b(%12.3f) ar2(%8.2f) se(%8.3f)  star(* 0.1 ** 0.05 *** 0.01) /// 
		cells("b(fmt(3)star)" "se(fmt(3)par)")  ///
		stats(industryYear state fin geo additional  r2_a N, fmt(%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.2fc %9.0fc) ///
		labels("Industry x Year FE" "State FE" "Financial Controls" "Geographic Controls" "Additional Controls"  "Adjusted R2" "Obs.")) /// 
		keep(BP_CBSA weighted_input_concentration weighted_output_concentration local_industry_conc ) ///
		coeflabels(BP_CBSA "Best Place" weighted_input_concentration "Concentration of Input Industries" weighted_output_concentration "Concentration of Output Industries" local_industry_conc "Concentration of Own Industry"  )  ///
		nonotes
		
***********************************************************************************
******************  Size Placebo Tests for Figure D.1  ****************************
***********************************************************************************	
	
*Size placebo
capture program drop sim1
program define sim1, rclass
	preserve
	gen placebo_size = .
	gen random = runiform()
	replace placebo_size = 1 if random<.2
	replace placebo_size =2 if random>=0.2 & random<.8
	replace placebo_size =3 if random>=0.8
	
	*Group 1
	reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels if placebo_size==1, absorb(ind_code_48##year state_id) cluster(cbsa)
	return scalar test_coef_1 =_b[BP_CBSA]
	return scalar se_coef_1=_se[BP_CBSA]
	return scalar t_coef_1 =_b[BP_CBSA]/_se[BP_CBSA]
	*Group 2
	reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels if placebo_size==2, absorb(ind_code_48##year state_id) cluster(cbsa)
	return scalar test_coef_2 =_b[BP_CBSA]
	return scalar se_coef_2=_se[BP_CBSA]
	return scalar t_coef_2 =_b[BP_CBSA]/_se[BP_CBSA]
	*Group 3
	reghdfe l_Price BP_CBSA c.BM_cbsa c.(${fin_controls}) c.(${local_controls}) $channels if placebo_size==3, absorb(ind_code_48##year state_id) cluster(cbsa)
	return scalar test_coef_3 =_b[BP_CBSA]
	return scalar se_coef_3=_se[BP_CBSA]
	return scalar t_coef_3 =_b[BP_CBSA]/_se[BP_CBSA]
	ereturn clear
	restore
	
end

preserve
set seed 14092023
simulate, reps(1000) : sim1

local small = -.026
local medium = .137
local big = -.059

local small_t = -0.84
local medium_t  = 4.17
local big_t = -0.59

sum t_coef_1
local avg_t_small = round(`r(mean)',.001)
sum t_coef_2
local avg_t_med =  round(`r(mean)',.001)
sum t_coef_3
local avg_t_big =  round(`r(mean)',.001)

sum test_coef_1
local avg_coef_small = round(`r(mean)',.001)
sum test_coef_2
local avg_coef_med =  round(`r(mean)',.001)
sum test_coef_3
local avg_coef_big =  round(`r(mean)',.001)


graph drop _all

twoway (histogram test_coef_1 ,  xline(`small') name("SmallCoeff") /// 
	graphregion(fcolor(white) lcolor(none) ifcolor(none) ilcolor(none)) ///
	plotregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) ///
	yscale(range(0 .3)) ylabel(0(.05).3) ///
	xscale(range(-.07 0.4)) xlabel(-0.05(.05)0.4) ///
	fraction xtitle("Coefficients: Small") text(0.225 0.025 "Actual Coeff. = `small'" ))
	
twoway (histogram test_coef_2 , xline(`medium') name("MediumCoeff") /// 
	graphregion(fcolor(white) lcolor(none) ifcolor(none) ilcolor(none)) ///
	plotregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) ///
	yscale(range(0 .3)) ylabel(0(.05).3) ///
	xscale(range(-.07 0.4)) xlabel(-0.05(.05)0.4) ///
	fraction xtitle("Coefficients: Medium")  text(0.225 0.185 "Actual Coeff. = `medium'" ))
	
twoway (histogram test_coef_3 ,  xline(`big') name("BigCoeff") /// 
	graphregion(fcolor(white) lcolor(none) ifcolor(none) ilcolor(none)) ///
	plotregion(fcolor(none) lcolor(none) ifcolor(none) ilcolor(none)) ///
	yscale(range(0 .3)) ylabel(0(.05).3) ///
	xscale(range(-.07 0.4)) xlabel(-0.05(.05)0.4) ///
	fraction xtitle("Coefficients: Big") text(0.225 -0.005 "Actual Coeff. = `big'" ))
	
graph  combine SmallCoeff MediumCoeff BigCoeff, rows(3) /// 
	graphregion(fcolor(white) lcolor(none) ifcolor(none) ilcolor(none)) plotregion(fcolor(none) ///
	lcolor(none) ifcolor(none) ilcolor(none)) name("PlaceboCoef")
graph export "${Tables}\Placebo_Size_coeff.pdf", as(pdf) name("PlaceboCoef") replace

restore
	
